package br.pucrs.prototipoonline.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.pucrs.prototipoonline.facade.ProjetosFacade;
import br.pucrs.prototipoonline.json.ProjetoJS;
import br.pucrs.prototipoonline.util.JSONUtil;
import br.pucrs.prototipoonline.vo.ProjetoVO;


/**
 * 
 * @author Ricardo Luckei
 * @author Gelson Gentil
 *
 */
public class BuscarProjetoCompletoAction extends POAjaxAction {

	private Logger logger = Logger.getLogger(BuscarProjetoCompletoAction.class);
	
	public ActionForward executar(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		logger.info("Entrando");
		
		String projetoId = request.getParameter("projetoId");
		
		ProjetosFacade facade = (ProjetosFacade) getFacade(ProjetosFacade.class);
		ProjetoVO projVO = new ProjetoVO();
		projVO.setId(Integer.valueOf(projetoId));
		projVO = facade.buscarProjetoCompleto(projVO);
		
		ProjetoJS projJS = JSONUtil.convertToJson(projVO);
		String json = JSONUtil.toJson(projJS);
		logger.debug(json);
		
		writeOutput(json);
		
		logger.info("Saindo");
		return null;
	}
}
